<?php
class comment_model_adminstate extends Model {

	public  function __construct(){
			parent::__construct();
			$this->table = 'app_com_state';
	}
	
	public function getStateDate($page, $verify, $isdelete)
	{
		$sql	= "select * from  " . $this->table . " where `delete` = " . $isdelete . " and verify = " . $verify . " order by create_time desc";
		$params = array();
		return $this->db->selectPage($sql,$params,$page,30);		 
	
	}
	
	//统计数据
	public function allStateCount()
	{
			$sql	=	"select count(*) as num from " . $this->table ;
			$result =	$this->db->fetchRow($sql);
			$data['allnum']	= $result['num'];
			
			$sql_del = "select count(*)  as num from " . $this->table . " where `delete` = 1 ";
			$result_del	=	$this->db->fetchRow($sql_del);
			$data['delnum']	=	$result_del['num'];
			
			return $data;
	}
	
	//查询心情内容
	public function searchStateDate($page , $uid , $starttime , $endtime)
	{
			$condition = '';
			if ($uid) {
				$condition .= " uid = " . $uid . '  and  ';
			}
			if ($starttime && $endtime) {
	
					$condition .= " create_time BETWEEN  " . strtotime($starttime) . " and " . strtotime($endtime) . '  and  ' ;
			} else {
				if($starttime && $endtime == 0){

					$condition .= " create_time BETWEEN  " . strtotime($starttime) . " and " . time() . ' and ' ;
				}
			}
			if ($condition) {
				$sql = " select * from  " . $this->table . " where   " . $condition . "  `delete` = 0 " ;
				return $this->db->selectPage($sql, array(), $page, 30);
			}
	}
	
	//统计心情条数
	public function searchstateCount($starttime,$endtime)
	{
			$sql	=	"select count(*) as num from " . $this->table . "  where create_time BETWEEN  " . $starttime . " and " . $endtime  ;
			$result =	$this->db->fetchRow($sql);
			$data['allnum']	=	$result['num'];
			
			$sql_del	= "select count(*)  as num from " . $this->table . " where `delete` != 0 and create_time BETWEEN  " . $starttime . " and " . $endtime  ;
	
			$result_del		=	$this->db->fetchRow($sql_del);
			$data['delnum']	=	$result_del['num'];
			
			return $data;		
	}
	
	//通过审核
	public function passNoverify($id)
	{
			$sql = " UPDATE  `app_com_state` SET  verify = 1 where id in ( " . $id . " ) ";
			return	$this->db->query($sql);
			
	}
	
	//删除心情数据
	public function adminDelState($id)
	{	
			$sql	=	"UPDATE  `app_com_state` SET `delete` = '2' and  verify = 1  WHERE `id` in ( " . $id . " ) ";
			return	$this->db->query($sql);	
	}
	
	//未审核数据
	public function getNoverifyData($page)
	{	
			$sql	=	" select * from " . $this->table . " where verify = 0 and `delete` = 0 ";
			$params = array();
			return $this->db->selectPage($sql,$params,$page,30);
	}
	
	//已审核数据
	public function getPassverifyData($page)
	{	
			$sql	=	" select * from " . $this->table . " where verify = 1 and `delete` = 0 ";
			$params = array();
			return $this->db->selectPage($sql,$params,$page,30);
	}

	//后台删除数据
	public function getAdmindelData($page)
	{	
			$sql	=	" select * from " . $this->table . " where  `delete` = 2  ";
			$params = array();
			return $this->db->selectPage($sql,$params,$page,30);
	}
	
		//恢复
	public function recoverdata($id)
	{
		$sql = "update " . $this->table . " set `deleted` = 0  where id  = $id ";
		return $this->db->query($sql);
	}
}
